package com.fengxu.gamescript.data.other;

import android.util.DisplayMetrics;
import com.fengxu.gamescript.util.CommonUtils;

import java.io.Serializable;

/**
 * 原神键位配置
 * @deprecated 启用的配置类型,请使用新的KeyConf
 */
@Deprecated
public class YsKeyConf implements Serializable {

    private static final long serialVersionUID = 001L;

    /**************** 下方四个属性由系统自动计算 ********************/
    // x轴方向开始的位置
    public static final double SystemXStart;
    // x轴心间距
    public static final double SystemXGep;
    // y轴方向开始的位置
    public static final double SystemYStart;
    // y轴间距
    public static final double SystemYGep;

    // 自动计算x,y的间距与位置
    static {
        // 获取竖屏时的系统宽高
        DisplayMetrics screenMetrics = CommonUtils.INSTANCE.getScreenMetric();
        // 计算间距
        int screenHeight = screenMetrics.heightPixels;
        int screenWidth = screenMetrics.widthPixels;
        double mh = 170.0;
        double mw = 210.0;
        SystemYGep = mh / 1080 * screenWidth;
        SystemYStart = (screenWidth + SystemYGep) / 2.0 - 10.0 / 1080 * screenWidth;
        SystemXGep = mw / 2340 * screenHeight;
        SystemXStart = (screenHeight - 7*SystemXGep + SystemXGep)/2;
    }

    // 下方用户可改变的x,y间距，中心距
    private Double xStart;
    // x轴心间距
    private Double xGep;
    // y轴方向开始的位置
    private Double yStart;
    // y轴间距
    private Double yGep;

    // 21键的位置
    private Point[] keyPoints = new Point[21];

    public double getxStart() {
        if(xStart == null) xStart = SystemXStart;
        return xStart;
    }

    public void setxStart(double xStart) {
        this.xStart = xStart;
    }

    public double getxGep() {
        if(xGep == null) xGep = SystemXGep;
        return xGep;
    }

    public void setxGep(double xGep) {
        this.xGep = xGep;
    }

    public double getyStart() {
        if(yStart == null) yStart = SystemYStart;
        return yStart;
    }

    public void setyStart(double yStart) {
        this.yStart = yStart;
    }

    public double getyGep() {
        if(yGep == null) yGep = SystemYGep;
        return yGep;
    }

    public void setyGep(double yGep) {
        this.yGep = yGep;
    }

    /**
     * 根据x,y侧边距和中心距重新计算原神的21键位
     */
    public void reCalcKeyPoints(){
        for (int i = 0; i < keyPoints.length; i++) {
            int yIndex =  i / 7;
            int xIndex = i % 7;
            keyPoints[i] = new Point(getxStart() + getxGep()*xIndex, getyStart() + getyGep()*yIndex);
        }
    }

    public Point[] getKeyPoints() {
        for (int i = 0; i < keyPoints.length; i++) {
            // 未赋值时计算键位
            if(keyPoints[i] == null){
                int yIndex =  i / 7;
                int xIndex = i % 7;
                keyPoints[i] = new Point(getxStart() + getxGep()*xIndex, getyStart() + getyGep()*yIndex);
            }
        }
        return keyPoints;
    }

    public void setKeyPoints(Point[] keyPoints) {
        this.keyPoints = keyPoints;
    }


}

